package cn.itsource.zcn.org.service.impl;

import cn.itsource.zcn.org.domain.Department;
import cn.itsource.zcn.org.mapper.DepartmentMapper;
import cn.itsource.zcn.org.query.DepartmentQuery;
import cn.itsource.zcn.org.service.IDepartmentService;
import cn.itsource.zcn.utils.QueryResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;


import java.util.List;

/**
 * (Department)表服务实现类
 *
 * @author makejava
 * @since 2021-08-06 16:14:36
 */
@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class DepartmentServiceImpl implements IDepartmentService {
    @Autowired
    private DepartmentMapper DepartmentMapper;


    /**
     * 新增数据
     * @param Department 实例对象
     */
    @Override
    @Transactional
    public void save(Department Department) {
        DepartmentMapper.save(Department);
    }

    /**
     * 修改数据
     * @param Department 实例对象
     */
    @Override
    @Transactional
    public void update(Department Department) {
        DepartmentMapper.update(Department);
    }

    /**
     * 通过主键删除数据
     * @param id 主键
     */
    @Override
    @Transactional
    public void delete(Long id) {
        DepartmentMapper.delete(id);
    }

    /**
     * 通过ID查询单条数据
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Department queryById(Long id) {
        return DepartmentMapper.queryById(id);
    }

    /**
     * 查询多条数据
     * @return 对象列表
     */
    @Override
    public List<Department> queryAll() {
        return DepartmentMapper.queryAll();
    }

    /**
     * 查询高级+分页数据
     * @return QueryResult
     */
    @Override
    public QueryResult queryPage(DepartmentQuery departmentQuery) {
        Integer count = DepartmentMapper.count(departmentQuery);
        if (count == 0){
            return new QueryResult();
        }
        List<Department> data = DepartmentMapper.query(departmentQuery);
        return new QueryResult<Department>(data,count);
    }
    /**
     * 批量删除
     * @return AjaxResult
     */
    @Override
    @Transactional
    public void patchDelete(Long[] ids) {
        DepartmentMapper.patchDelete(ids);
    }
}
